﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _3_2_Process
{
    class Program
    {
        static void Main(string[] args)
        {
            int max = Max(1234, 4567);
            Console.WriteLine(Max(789, Max(1234, 4567)));
            PrintMessage(max.ToString());

            PrintStar();

            bool flag = PrintMessage("auigujgjpsdoh;jp");
            PrintMessage(flag.ToString());

            PrintStar();

            Console.ReadKey();

            Test4(1);

            Test3();

            Test2();

            Test1();

            //最大公约数和最小公倍数
            Test();
            //九九*表
            for (int i1 = 1; i1 <= 9; i1++)
            {
                for (int j1 = 1; j1 <= i1; j1++)
                    Console.Write(j1 + "*" + i1 + "=" + i1 * j1 + " ");
                Console.WriteLine();
            }
            Console.ReadKey();
            //for for
            int iii, j=0, k = 0, m = 0;
            for (iii = 0; iii < 2; iii++)
            {
                for (j = 0; j < 3; j++)
                    k++;
                k -= j;
            }
            m = iii + j;

            //1*1 = 1
            //1*2 = 2  2*2 = 4   
            //1*3 = 3  2*3 = 6  3*3 = 9
            //......

            Console.WriteLine(iii + " " + j + " " + m + " " + k);
            //for (int i = 0, k = -1; k == 1; i++, k++)
                //Console.WriteLine("****");

            char ci, cj;
            for (ci = 'a', cj = 'z'; ci <= cj; ci++)
                Console.WriteLine(ci + "    " + (int)ci);
            Console.ReadKey();

            int whi = 0, sum = 0;
            //for 3
            for ( ; ; )
            {
                if (whi > 100)
                    break;
                //Console.WriteLine("{}...." + whi);
                sum += whi;
                whi++;
            }
            Console.WriteLine(sum);
            Console.ReadKey();
            //for 2
            for (whi = 1; whi <= 100;)
            {
                sum += whi;
                whi++;
            }
            Console.WriteLine(sum);
            Console.ReadKey();
            //for 1
            for (whi = 1; whi<=100; whi++)
            {
                sum += whi;
            }
            Console.WriteLine(sum);
            Console.ReadKey();
            //do while
            do
            {
                sum += whi;
                whi++;
            } while (whi <= 100);
            Console.WriteLine(sum);

            Console.ReadKey();
            //while
            while (whi-- != 0) Console.WriteLine(whi);
            Console.WriteLine(whi);
            Console.ReadKey();
            whi = 3;
            while (--whi!= 0) Console.WriteLine(whi);
            Console.WriteLine(whi);
            Console.ReadKey();


            //switch 2
            int x = 1, y = 0, a = 0, b = 0;
            switch (x)
            {
                case 1:
                    switch (y)
                    {
                        case 0: a++; break;
                        case 1: b++; break;
                    }

                    break;
                case 2:
                    a++; b++; break;
                case 3:
                    a++; b++; break;
            }

            Console.WriteLine(a + "   " + b);
            Console.ReadKey();
            //switch 1
            string grade = "AB";
            char test = 'C';
            switch(grade)
            {
                case "AB":
                    {
                        Console.WriteLine(grade);
                        break;
                    }
                case "DB": Console.WriteLine(grade); break;
                case "CC": Console.WriteLine(grade); break;
                case "DD": Console.WriteLine(grade); break;
                default: Console.WriteLine(grade); break;

            }
            Console.ReadKey();
        }


        static void Test4(int a)
        {
            Console.WriteLine("---------start--------");
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4 - i - 1; j++)
                {
                    Console.Write("   ");
                }
                for (int j = 0; j < 2 * i + 1; j++)
                {
                    Console.Write(" * ");
                }
                Console.WriteLine();
            }
            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < i + 1; j++)
                {
                    Console.Write("   ");
                }
                for (int j = 0; j < 2 * (3 - i - 1) + 1; j++)
                {
                    Console.Write(" * ");
                }
                Console.WriteLine();
            }

            Console.ReadKey();

            for (int i = 0; i < 3; i++)
            {
                for (int j = 0; j < i + 1; j++)
                {
                    Console.Write(" * ");
                }
                Console.WriteLine();
            }
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4 - i; j++)
                {
                    Console.Write(" * ");
                }
                Console.WriteLine();
            }

            Console.ReadKey();

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4 - i - 1; j++)
                {
                    Console.Write("   ");
                }
                for (int j = 0; j < i + 1; j++)
                {
                    Console.Write(" * ");
                }
                Console.WriteLine();
            }

            Console.ReadKey();

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4 - i; j++)
                {
                    Console.Write(" * ");
                }
                Console.WriteLine();
            }

            Console.ReadKey();
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    Console.Write(" * ");
                }
                Console.WriteLine();
            }

            Console.ReadKey();

            Console.WriteLine("---------西瓜--------");
            int day = 0, xigua = 1020;
            while (xigua != 0)
            {
                day++;
                xigua = xigua - (xigua / 2 + 2);
            }
            Console.WriteLine("需要: {0} 才能卖完", day);
            Console.ReadKey();

            Console.WriteLine("---------PI2--------");
            double sum = 0, temp = 1;
            for (int i = 1; i <= 1000; i++)
            {
                temp = (float)1 / (i * i);
                sum += temp;
            }
            Console.WriteLine("PI*PI: {0}", sum * 6);
            Console.ReadKey();

            Console.WriteLine("---------PI1--------");
            double s = 1, t = 1;
            for (float i = 1; i <= 1000; i++)
            {
                t = 2 * i / (2 * i - 1) * 2 * i / (2 * i + 1);
                s *= t;
            }
            Console.WriteLine("PI: {0}", 2 * s);
            Console.ReadKey();
            Console.WriteLine("---------131--------");
            for (int i = 1; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    for (int k = 0; k < 10; k++)
                    {
                        int temp1 = (i * i + j * j + k * k);
                        int temp2 = (i * 100 + j * 10 + k) / 11;

                        if ((temp1 == temp2) && (i == j || i == k || j == k))
                        {
                            //if (i == j || i == k || j == k)
                            Console.WriteLine("{0}{1}{2}", i, j, k);
                        }
                    }
                }
            }
            Console.ReadKey();
        }
        static void Test3()
        {
            Console.WriteLine("小于N的所有素数");
            //小于N的所有素数
            string con = "";
            do
            {
                Console.WriteLine("Please Enter a Num:");
                uint f1;
                while (!uint.TryParse(Console.ReadLine(), out f1) && f1 < 2)
                {
                    Console.WriteLine("Input Error! Please Enter a Num:");
                }
                int i, j;
                for (i = 2; i < f1; i++)
                {
                    for (j = 2; j <= i; j++)
                    {
                        if (i % j == 0)
                            break;
                    }
                    if (j == i)
                        Console.WriteLine("{0}\t是素数", i);
                }

                //30天多少钱
                double ret = 0, y = 0.01;
                for (int ii = 1; ii <= 30; ii++)
                {
                    ret += y;
                    y = y * 2;
                }
                Console.Write("\n 30: {0}\n", ret);
                //星号打印
                int k = 0;
                for (i = 0; i < 4; i++)
                {
                    for (j = 4 - i - 1; j > 0; j--)
                        Console.Write("   ");
                    for (k = 1; k <= i + 1; k++)
                        Console.Write(" * ");
                    Console.Write("\n\n");
                }
                for (i = 3; i >= 0; i--)
                {
                    for (k = 1; k <= i; k++)
                        Console.Write(" * ");
                    Console.Write("\n\n");
                }

                int sum = 0;
                int temp = 2;

                for (int count = 1; count < 7; count++)
                {
                    sum += temp;
                    temp = temp * 10 + 2;

                }
                Console.WriteLine(sum);

                Console.WriteLine("是否继续？（Y/N）");
                con = Console.ReadLine();
            } while (con == "Y" || con == "y");
            Console.ReadKey();
        }
        static void Test2()
        {
            int k = 0;
            char c = 'A';
            do
            {
                switch (c++)
                {
                    case 'A': k++; break;
                    case 'B': k--; continue;
                    case 'C': k += 2; break;
                    case 'D': k = k % 2; continue;
                    case 'E': k = k * 10; break;
                    default: k = k / 3; break;
                }
                k++;
                if (c < 'G')
                    break;
                Console.WriteLine(k);
            } while (true);
            Console.ReadKey();
        }
        static void Test1()
        {
            Console.WriteLine("求级数公式");
            //求级数公式
            string con = "";
            do
            {
                Console.WriteLine("Please Enter a Num N:");
                uint f1;
                while (!uint.TryParse(Console.ReadLine(), out f1) && f1 < 1)
                {
                    Console.WriteLine("Input Error! Please Enter a Num:");
                }
                Console.WriteLine("Please Enter anthor Num X:");
                float f2;
                while (!float.TryParse(Console.ReadLine(), out f2))
                {
                    Console.WriteLine("Input Error! Please Enter anthor Num:");
                }

                int n = 1;
                double S = 0, temp = 1;
                while (n <= f1)
                {
                    S += temp;
                    temp = (-1) * temp * f2 * f2 / ((2 * n) * (2 * n - 1));
                    n++;
                }
                Console.WriteLine("S:" + S);
                Console.WriteLine("是否继续？（Y/N）");
                con = Console.ReadLine();
            } while (con == "Y" || con == "y");
            Console.ReadKey();
        }


        static bool PrintMessage(string s)
        {
            Console.WriteLine("PrintMessage:" + s);
            return true;
        }

        static void PrintStar()
        {
            Console.WriteLine("*******************");
        }

        static int Max(int a, int b)
        {
            //int ret = 0;
            //ret = a > b ? a : b;
            /*
            if (a > b)
                ret = a;
            else
                ret = b;
            */
            //return ret;
            return a > b ? a : b;
        }


        static bool Test()
        {
            Console.WriteLine("最大公约数和最小公倍数");
            //最大公约数和最小公倍数
            string con = "";
            do
            {
                Console.WriteLine("Please Enter a Num:");
                uint f1;
                while (!uint.TryParse(Console.ReadLine(), out f1) && f1 < 1)
                {
                    Console.WriteLine("Input Error! Please Enter a Num:");
                }

                Console.WriteLine("Please Enter anthor Num:");
                uint f2;
                while (!uint.TryParse(Console.ReadLine(), out f2) && f2 < 1)
                {
                    Console.WriteLine("Input Error! Please Enter anthor Num:");
                }

                uint min = f1, max = f2;
                if (f1 > f2)
                {
                    min = f2;
                    max = f1;
                }
                uint r = max % min;

                for (uint i = 1; i < min; i++)
                    if (max % i == 0 && min % i == 0)
                    {
                        r = i;
                    }
                Console.WriteLine("最大公约数：{0}  最小公倍数：{1}", r, f1 * f2 / r);

                r = max % min;

                while (r != 0)
                {

                    max = min;
                    min = r;
                    r = max % min;
                    Console.WriteLine(r);
                }
                Console.WriteLine("最大公约数：{0}  最小公倍数：{1}", min, f1 * f2 / min);
                Console.WriteLine("是否继续？（Y/N）");
                con = Console.ReadLine();
            } while (con == "Y" || con == "y");
            Console.ReadKey();
            return true;
        }
    }
}
